//
//  CMutSoundPlayW.m
//  3GuoTD
//
//  Created by waver on 10-8-17.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "CMutSoundPlayW.h"


static CMutSoundPlayW * __self = nil;

@implementation CMutSoundPlayW

+(id)MutSoundPlayShare
{
	if(__self == nil)
	{
		__self = [[super alloc] initSound];
	}
	
	return __self;
}

-(id)initSound
{
	for(int i=0;i<(int)S_MAX;i++)
	{
		__pitch[i] = 1.0;
		__gain[i] = 1.0;
		__pan[i] = 0.5;
	}
	__playMusic = [SimpleAudioEngine sharedEngine];
	
	for(int i=0;i<(int)S_MAX;i++)
	{
		//__playSound[i] = [[CDSoundEngine alloc]init:1];
		__playSound[i] = [[CDSoundEngine alloc]init];
		
	}
	[__playSound[0] loadBuffer:0 filePath:@"two.wav"];
	/*
	[__playSound[1] loadBuffer:1 filePath:@"three.wav"];
	[__playSound[2] loadBuffer:2 filePath:@"four1.wav"];
	[__playSound[3] loadBuffer:3 filePath:@"four2.wav"];
	[__playSound[4] loadBuffer:4 filePath:@"four3.wav"];
	[__playSound[5] loadBuffer:5 filePath:@"four4.wav"];
	[__playSound[6] loadBuffer:6 filePath:@"four5.wav"];
	[__playSound[7] loadBuffer:7 filePath:@"four6.wav"];
	 */
	[self LoadSound];
	return self;
}

-(void)LoadSound
{
	
	__playMusic.backgroundMusicVolume = 1.0;
	__playMusic.effectsVolume = 1.0;
	[__playMusic preloadEffect:@"three.wav"];
	[__playMusic preloadBackgroundMusic:@"one.wav"];
	
}

-(void)PlayGameSound
{
	[__playMusic playBackgroundMusic:@"one.wav" loop:YES];
	
	[self PlaySound:0];
//	for(int i=0;i<1;i++)
//	{
//		[self PlaySound:i];
//	}
}

-(void)PlaySound:(int)groundId
{
	[__playSound[groundId] playSound:groundId sourceGroupId:0 pitch:1.0 pan:1.0 gain:0.5 loop:YES];
}

-(void)MutSound:(int)groundId MutState:(BOOL)isMut;
{
	[__playSound[groundId] setMute:isMut];
}

-(void)SetMusicVolume:(float)m_volume
{
	__playMusic.backgroundMusicVolume = m_volume;
}

-(void)SetEffectVolume:(float)e_volume
{
	__playMusic.effectsVolume = e_volume;
}

-(void)PlayEffectSound:(NSString *)fileName
{
	[__playMusic playEffect:fileName];
}

@end
